{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1733d174-b8b6-4350-8a3a-08126b486e8f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from cycler import cycler\n",
    "import statsmodels.formula.api as smf\n",
    "from statsmodels.iolib.summary2 import summary_col\n",
    "import os\n",
    "pathtodata=os.getcwd()+r\"\\vdemV14.csv\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6bf8017a-a67f-4dbd-9e37-4c2af1de918c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#For more on the V-Dem dataset see: V-Dem [Country-Year/Country-Date] Dataset v14. Gothenburg: Varieties of Democracy (V-Dem) Project. https://doi.org/10.23696/mcwt-fr58.\n",
    "#For variable definitions, see codebook at: V-Dem Codebook v14. https://www.vdem.net/data/dataset-archive."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7d7f0eaa-8d5e-4156-b857-40fca0011e33",
   "metadata": {},
   "outputs": [],
   "source": [
    "thevars=[\n",
    "    'country_text_id',\n",
    "    'country_name',\n",
    "    'year', \n",
    "    #Variables from V-Dem CY data version 14 & additional information from World Bank. 2024. World Development Indicators. Washington, DC: World Bank. https://data.worldbank.org/products/wdi.\n",
    "         'e_pop',\n",
    "         'e_gdppc',\n",
    "    #Variables from V-Dem CY data version 14:\n",
    "         'v2x_regime', #starts in 1900\n",
    "         'e_miinterc_orig', #internal war, 1789-2000\n",
    "        'v2clslavem_ord', #Male slavery\n",
    "        'v2clslavef_ord', #Female slavery\n",
    "         'v2cldmovem_ord', #Male freedom movement\n",
    "         'v2cldmovew_ord', #Female freedom movement    \n",
    "        'v2clstown_ord', #state economic ownership\n",
    "         'v2pepwrgeo_ord', #Power distributed by urban-rural location (C) \n",
    "        'v2clgeocl_ord', #Urban-rural location equality in respect for civil liberties (C) (v2clgeocl) \n",
    "         'v2peapsgeo_ord', #Access to public services distributed by urban-rural location (C) (v2peapsgeo)\n",
    "        'v2peasjgeo_ord', # 3.13.3.4 Access to state jobs by urban-rural location (C) (v2peasjgeo) \n",
    "         'v2peasbegeo_ord', #Access to state business opportunities by urban-rural location (C) (v2peasbegeo)\n",
    "          'v2exl_legitideolcr_1', #state ideology = socialist\n",
    "    #Variables from VDem brought up to date with UCDP Country Year Dataset on Organized Violence within Country Borders. See: Sundberg, Ralph, and Erik Melander, 2013, “Introducing the UCDP Georeferenced Event Dataset”, Journal of Peace Research, vol.50, no.4, 523-532\n",
    "    'e_miinterc' #Civil war\n",
    "        ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b8469486-aa6a-41a7-b888-3c69761fa7a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>country_text_id</th>\n",
       "      <th>year</th>\n",
       "      <th>country_name</th>\n",
       "      <th>democracy</th>\n",
       "      <th>e_pop</th>\n",
       "      <th>e_gdppc</th>\n",
       "      <th>e_miinterc</th>\n",
       "      <th>v2clslavem_ord</th>\n",
       "      <th>v2clslavef_ord</th>\n",
       "      <th>v2cldmovem_ord</th>\n",
       "      <th>v2cldmovew_ord</th>\n",
       "      <th>v2clstown_ord</th>\n",
       "      <th>v2pepwrgeo_ord</th>\n",
       "      <th>v2clgeocl_ord</th>\n",
       "      <th>v2peapsgeo_ord</th>\n",
       "      <th>v2peasjgeo_ord</th>\n",
       "      <th>v2peasbegeo_ord</th>\n",
       "      <th>v2exl_legitideolcr_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>MEX</td>\n",
       "      <td>1789</td>\n",
       "      <td>Mexico</td>\n",
       "      <td>NaN</td>\n",
       "      <td>645627.0</td>\n",
       "      <td>1.352</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MEX</td>\n",
       "      <td>1790</td>\n",
       "      <td>Mexico</td>\n",
       "      <td>NaN</td>\n",
       "      <td>647112.0</td>\n",
       "      <td>1.357</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MEX</td>\n",
       "      <td>1791</td>\n",
       "      <td>Mexico</td>\n",
       "      <td>NaN</td>\n",
       "      <td>647464.0</td>\n",
       "      <td>1.371</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MEX</td>\n",
       "      <td>1792</td>\n",
       "      <td>Mexico</td>\n",
       "      <td>NaN</td>\n",
       "      <td>649721.0</td>\n",
       "      <td>1.389</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>MEX</td>\n",
       "      <td>1793</td>\n",
       "      <td>Mexico</td>\n",
       "      <td>NaN</td>\n",
       "      <td>650911.0</td>\n",
       "      <td>1.401</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  country_text_id  year country_name  democracy     e_pop  e_gdppc  \\\n",
       "0             MEX  1789       Mexico        NaN  645627.0    1.352   \n",
       "1             MEX  1790       Mexico        NaN  647112.0    1.357   \n",
       "2             MEX  1791       Mexico        NaN  647464.0    1.371   \n",
       "3             MEX  1792       Mexico        NaN  649721.0    1.389   \n",
       "4             MEX  1793       Mexico        NaN  650911.0    1.401   \n",
       "\n",
       "   e_miinterc  v2clslavem_ord  v2clslavef_ord  v2cldmovem_ord  v2cldmovew_ord  \\\n",
       "0         0.0             1.0             0.0             3.0             3.0   \n",
       "1         0.0             1.0             0.0             3.0             3.0   \n",
       "2         0.0             1.0             0.0             3.0             3.0   \n",
       "3         0.0             1.0             0.0             3.0             3.0   \n",
       "4         0.0             1.0             0.0             3.0             3.0   \n",
       "\n",
       "   v2clstown_ord  v2pepwrgeo_ord  v2clgeocl_ord  v2peapsgeo_ord  \\\n",
       "0            2.0             NaN            NaN             NaN   \n",
       "1            2.0             NaN            NaN             NaN   \n",
       "2            2.0             NaN            NaN             NaN   \n",
       "3            2.0             NaN            NaN             NaN   \n",
       "4            2.0             NaN            NaN             NaN   \n",
       "\n",
       "   v2peasjgeo_ord  v2peasbegeo_ord  v2exl_legitideolcr_1  \n",
       "0             NaN              NaN                   NaN  \n",
       "1             NaN              NaN                   NaN  \n",
       "2             NaN              NaN                   NaN  \n",
       "3             NaN              NaN                   NaN  \n",
       "4             NaN              NaN                   NaN  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vdem=pd.read_csv(pathtodata,low_memory=False,index_col=0)\n",
    "vdem.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9544d38e-48cd-4637-a641-34bb3bb10e07",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    27735.000000\n",
       "mean      1928.988138\n",
       "std         64.707819\n",
       "min       1789.000000\n",
       "25%       1881.000000\n",
       "50%       1939.000000\n",
       "75%       1984.000000\n",
       "max       2023.000000\n",
       "Name: year, dtype: float64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vdem.year.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "53d9b12e-33aa-42a5-82ee-fa4c858d8ab7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    19494.000000\n",
       "mean         0.127526\n",
       "std          0.333570\n",
       "min          0.000000\n",
       "25%          0.000000\n",
       "50%          0.000000\n",
       "75%          0.000000\n",
       "max          1.000000\n",
       "Name: dommoverestrict_01, dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Domestic movement restrictions\n",
    "vdem['v2cldmovea_rev']=(4-(vdem['v2cldmovem_ord']+vdem['v2cldmovew_ord'])/2)/4\n",
    "#vdem.loc[pd.isna(vdem.v2cldmovew_ord),'v2cldmovea_rev']=(4-vdem['v2cldmovem_ord'])/4\n",
    "conditions=[\n",
    "    vdem['v2cldmovea_rev']<=0.5,\n",
    "    vdem['v2cldmovea_rev']>0.5\n",
    "]\n",
    "choices=[0,1]\n",
    "vdem['dommoverestrict_01']=pd.to_numeric(np.select(conditions,choices,default=None))\n",
    "vdem.loc[vdem.year>1899,'dommoverestrict_01'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f1f675b6-1e62-45c5-8149-70e53e32bee0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    123.000000\n",
       "mean       0.227642\n",
       "std        0.421025\n",
       "min        0.000000\n",
       "25%        0.000000\n",
       "50%        0.000000\n",
       "75%        0.000000\n",
       "max        1.000000\n",
       "Name: dommoverestrict_01, dtype: float64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Summary statistics 1900 and 2023\n",
    "vdem.loc[vdem.year==1900,'dommoverestrict_01'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ecea650a-e21a-47f3-b8e5-382b96584cc5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    179.000000\n",
       "mean       0.022346\n",
       "std        0.148222\n",
       "min        0.000000\n",
       "25%        0.000000\n",
       "50%        0.000000\n",
       "75%        0.000000\n",
       "max        1.000000\n",
       "Name: dommoverestrict_01, dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Summary statistics 1900 and 2023\n",
    "vdem.loc[vdem.year==2023,'dommoverestrict_01'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "42439428-bfe7-4687-8252-affa6bd66f02",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Coerced labor\n",
    "vdem['v2clslavea_rev']=(4-(vdem['v2clslavem_ord']+vdem['v2clslavef_ord'])/2)/4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "78880889-7715-4fbb-aabe-3d189e127693",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Geographic inequality - politics\n",
    "for x,y in zip(['v2pepwrgeo', #power\n",
    "         'v2clgeocl'] #civil liberties\n",
    "            ,['pol','cl']):\n",
    "    vdem[x+'_rev']=(4-vdem[x+'_ord'])/4\n",
    "    vdem.loc[vdem[x+'_ord']==5,x+'_rev']=0.5\n",
    "vdem['geopolbias']=(vdem['v2pepwrgeo_rev']+vdem['v2clgeocl_rev'])/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bff23237-25f8-4f9d-957a-ef30d4969c4c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Geographic inequality - state economic services\n",
    "for x,y in zip(['v2peapsgeo', #public services\n",
    "         'v2peasjgeo', #state jobs\n",
    "         'v2peasbegeo' #state business\n",
    "         ],['ps','sj','sb']):\n",
    "    vdem[x+'_rev']=(4-vdem[x+'_ord'])/4\n",
    "    vdem.loc[vdem[x+'_ord']==5,x+'_rev']=0.75 #5 equivalent to 1 for rural areas\n",
    "vdem['geoeconbias']=(vdem['v2peapsgeo_rev']+vdem['v2peasjgeo_rev']+vdem['v2peasbegeo_rev'])/3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "908d7859-a699-4a94-b608-797b5773c2cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "#Command economy and market socialists\n",
    "vdem['stateown_rev']=(4-vdem['v2clstown_ord'])/4\n",
    "conditions=[\n",
    "    ((vdem['stateown_rev']>0.5)&(vdem['v2exl_legitideolcr_1']<=0.5)),\n",
    "    ((vdem['stateown_rev']>0.5)&(vdem['v2exl_legitideolcr_1']>0.5)),\n",
    "    ((vdem['stateown_rev']<=0.5)&(vdem['v2exl_legitideolcr_1']<=0.5)),\n",
    "    ((vdem['stateown_rev']<=0.5)&(vdem['v2exl_legitideolcr_1']>0.5))\n",
    "]\n",
    "choices=['CommandEconomy','CommandEconomy','MarketOther','MarketSocialist']\n",
    "vdem['socialdems']=np.select(conditions,choices,default=None)\n",
    "choices=[1,1,0,0]\n",
    "vdem['command01']=np.select(conditions,choices,default=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6485d452-57f4-4a26-9fe0-919d0a7efa8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18456.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<class 'statsmodels.stats.contrast.ContrastResults'>\n",
       "                             Test for Constraints                             \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "c0             0.0352      0.007      4.802      0.000       0.021       0.050\n",
       "=============================================================================="
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "civilwar=smf.ols(formula=\"dommoverestrict_01 ~ e_miinterc + C(year) + C(country_text_id)\", data=vdem.loc[vdem.year>1899]).fit()\n",
    "print(civilwar.nobs)\n",
    "civilwar.t_test('e_miinterc = 0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "96a3fa0b-5c7d-4ad4-a658-caf1f1d1e381",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19494.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<class 'statsmodels.stats.contrast.ContrastResults'>\n",
       "                             Test for Constraints                             \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "c0             0.5967      0.010     57.927      0.000       0.577       0.617\n",
       "=============================================================================="
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "coercedlabor=smf.ols(formula=\"dommoverestrict_01 ~ v2clslavea_rev + C(year) + C(country_text_id)\", data=vdem.loc[vdem.year>1899]).fit()\n",
    "print(coercedlabor.nobs)\n",
    "coercedlabor.t_test('v2clslavea_rev = 0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "dab91a7e-f935-470f-8e38-413c21105947",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19494.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<class 'statsmodels.stats.contrast.ContrastResults'>\n",
       "                             Test for Constraints                             \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "c0             0.3009      0.011     28.201      0.000       0.280       0.322\n",
       "=============================================================================="
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "commandecon=smf.ols(formula=\"dommoverestrict_01 ~ stateown_rev + C(year) + C(country_text_id)\",  data=vdem.loc[vdem.year>1899]).fit()\n",
    "print(commandecon.nobs)\n",
    "commandecon.t_test('stateown_rev = 0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f5ae9de9-3bde-43da-a5f8-0bdc6c659cba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19125.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<class 'statsmodels.stats.contrast.ContrastResults'>\n",
       "                             Test for Constraints                             \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "c0             0.1831      0.006     32.373      0.000       0.172       0.194\n",
       "=============================================================================="
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "commandecon=smf.ols(formula=\"dommoverestrict_01 ~ command01 + C(year) + C(country_text_id)\",  data=vdem.loc[vdem.year>1899]).fit()\n",
    "print(commandecon.nobs)\n",
    "commandecon.t_test('command01[T.1] = 0')\n",
    "# summary_col(commandecon)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "507ed25a-55e6-4546-af99-259403865f63",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18938.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<class 'statsmodels.stats.contrast.ContrastResults'>\n",
       "                             Test for Constraints                             \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "c0             0.4029      0.013     29.852      0.000       0.376       0.429\n",
       "=============================================================================="
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geoineqpol=smf.ols(formula=\"dommoverestrict_01 ~ geopolbias + C(year) + C(country_text_id)\",  data=vdem.loc[vdem.year>1899]).fit()\n",
    "print(geoineqpol.nobs)\n",
    "geoineqpol.t_test('geopolbias = 0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "a10d691f-67b0-4635-942e-e661e018736b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18883.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<class 'statsmodels.stats.contrast.ContrastResults'>\n",
       "                             Test for Constraints                             \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "c0             0.2002      0.018     11.273      0.000       0.165       0.235\n",
       "=============================================================================="
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geoineqecon=smf.ols(formula=\"dommoverestrict_01 ~ geoeconbias + C(year) + C(country_text_id)\",  data=vdem.loc[vdem.year>1899]).fit()\n",
    "print(geoineqecon.nobs)\n",
    "geoineqecon.t_test('geoeconbias = 0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f56859b2-7b4e-4b87-851f-6fb43f462b83",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19125.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<class 'statsmodels.stats.contrast.ContrastResults'>\n",
       "                             Test for Constraints                             \n",
       "==============================================================================\n",
       "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
       "------------------------------------------------------------------------------\n",
       "c0            -0.0806      0.008     -9.642      0.000      -0.097      -0.064\n",
       "=============================================================================="
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "socdem=smf.ols(formula=\"dommoverestrict_01 ~ C(socialdems, Treatment(reference=\\'CommandEconomy\\')) + C(year) + C(country_text_id)\", data=vdem.loc[vdem.year>1899]).fit()\n",
    "print(socdem.nobs)\n",
    "socdem.t_test('C(socialdems, Treatment(reference=\\'CommandEconomy\\'))[T.MarketSocialist] - C(socialdems, Treatment(reference=\\'CommandEconomy\\'))[T.MarketOther] = 0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "306932bf-df46-4ee9-8d87-4ce9895f23a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15584.0\n",
      "\n",
      "===============================================================================================================================================================================================================================================\n",
      "                                                                        dommoverestrict_01 I dommoverestrict_01 II dommoverestrict_01 III dommoverestrict_01 IIII dommoverestrict_01 IIIII dommoverestrict_01 IIIIII dommoverestrict_01 IIIIIII\n",
      "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
      "e_miinterc                                                              0.035***                                                                                                                                     0.047***                  \n",
      "                                                                        (0.007)                                                                                                                                      (0.006)                   \n",
      "v2clslavea_rev                                                                               0.597***                                                                                                                0.573***                  \n",
      "                                                                                             (0.010)                                                                                                                 (0.013)                   \n",
      "command01[T.1]                                                                                                     0.183***                                                                                                                    \n",
      "                                                                                                                   (0.006)                                                                                                                     \n",
      "geopolbias                                                                                                                                0.403***                                                                   0.223***                  \n",
      "                                                                                                                                          (0.013)                                                                    (0.017)                   \n",
      "geoeconbias                                                                                                                                                       0.200***                                           -0.004                    \n",
      "                                                                                                                                                                  (0.018)                                            (0.021)                   \n",
      "C(socialdems, Treatment(reference='CommandEconomy'))[T.MarketOther]                                                                                                                        -0.176***                 -0.113***                 \n",
      "                                                                                                                                                                                           (0.006)                   (0.006)                   \n",
      "C(socialdems, Treatment(reference='CommandEconomy'))[T.MarketSocialist]                                                                                                                    -0.257***                 -0.169***                 \n",
      "                                                                                                                                                                                           (0.009)                   (0.009)                   \n",
      "democracy                                                                                                                                                                                                            0.078***                  \n",
      "                                                                                                                                                                                                                     (0.008)                   \n",
      "np.log(e_pop)                                                                                                                                                                                                        0.005                     \n",
      "                                                                                                                                                                                                                     (0.006)                   \n",
      "np.log(e_gdppc)                                                                                                                                                                                                      0.001                     \n",
      "                                                                                                                                                                                                                     (0.005)                   \n",
      "R-squared                                                               0.513                0.585                 0.530                  0.526                   0.507                    0.532                     0.603                     \n",
      "R-squared Adj.                                                          0.505                0.578                 0.522                  0.518                   0.499                    0.525                     0.595                     \n",
      "===============================================================================================================================================================================================================================================\n",
      "Standard errors in parentheses.\n",
      "* p<.1, ** p<.05, ***p<.01\n"
     ]
    }
   ],
   "source": [
    "controls=' + democracy + np.log(e_pop) + np.log(e_gdppc)'\n",
    "wcontrols=smf.ols(formula=\"dommoverestrict_01 ~ e_miinterc + v2clslavea_rev + geopolbias + geoeconbias + C(socialdems, Treatment(reference=\\'CommandEconomy\\')) + C(year) + C(country_text_id)\"+controls, \n",
    "                   data=vdem.loc[vdem.year>1899]).fit()\n",
    "print(wcontrols.nobs)\n",
    "print(summary_col([civilwar,coercedlabor,commandecon,geoineqpol,geoineqecon,socdem,wcontrols\n",
    "                   ],stars=True,float_format='%0.3f',\n",
    "                  regressor_order=['e_miinterc','v2clslavea_rev','command01[T.1]','geopolbias','geoeconbias',\n",
    "                                   'C(socialdems, Treatment(reference=\\'CommandEconomy\\'))[T.MarketOther]',\n",
    "                                   'C(socialdems, Treatment(reference=\\'CommandEconomy\\'))[T.MarketSocialist]',\n",
    "                                   'democracy',\n",
    "                                   'np.log(e_pop)',\n",
    "                                   'np.log(e_gdppc)'\n",
    "                                  ],\n",
    "                  drop_omitted=True\n",
    "                  ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ab1baa2-2322-489a-bf10-0b99ae3ce2fb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59a291a9-3a21-4470-93fd-d482419b816e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
